package reflect;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo4 {
    public static void main(String[] args) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException {
//        Scanner sc = new Scanner(System.in);
//        System.out.print("请输入类名:");
//        String className = sc.nextLine();//此处打点
//        System.out.print("请输入方法名:");
//        String methodName = sc.nextLine();
//        Class cls = Class.forName(className);
//        Object o = cls.newInstance();
//        Method method = cls.getMethod(methodName);
//        method.invoke(o);
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入类名:");
        String className = sc.nextLine();//此处打点
        Class cls = Class.forName(className);
        Method[] methods = cls.getDeclaredMethods();
        //  此处修改      复制使用 : reflect.Student
        for (int i = 0; i < methods.length; i++) {
            System.out.println(methods[i].getName());
        }
//        for (Method m:methods
//             ) {
//            System.out.println(m.getName());
//        }
        System.out.print("请输入方法名:");
        String methodName = sc.nextLine();

        Object o = cls.newInstance();
        Method method = cls.getMethod(methodName);
        method.invoke(o);
    }
}
